package com.desire.homework;

/**
 * @author desire
 */
public class _17_求数组最大最小值 {
    public static void main(String[] args) {
        int[] arr = new int[]{12, 57, 3, 2, 7, 2, 1, -15};
        System.out.println("最大值: " + maxNum(arr));
        System.out.println("最小值: " + minNum(arr));
    }

    public static int minNum(int... arr) {
        if (arr.length > 0) {
            int min = arr[0];
            for (int i = 1; i < arr.length; i++) {
                if (min > arr[i]) {
                    min = arr[i];
                }
            }
            return min;
        } else {
            return 0;
        }
    }

    public static int maxNum(int... arr) {
        if (arr.length > 0) {
            int max = arr[0];
            for (int i : arr) {
                if (max < i) {
                    max = i;
                }
            }
            return max;
        } else {
            return 0;
        }
    }
}
